package backpage.mapper;

import backpage.entity.SalaryLevel;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface SalaryLevelMapper {
    @Insert("INSERT INTO salary_level(salary_level_name, base_salary, annual_salary_days, max_consecutive_vacation_days) " +
            "VALUES(#{salaryLevelName}, #{baseSalary}, #{annualSalaryDays}, #{maxConsecutiveVacationDays})")
    @Options(useGeneratedKeys = true, keyProperty = "salaryLevelId")
    int insert(SalaryLevel salaryLevel);

    @Update("UPDATE salary_level SET salary_level_name=#{salaryLevelName}, base_salary=#{baseSalary}, " +
            "annual_salary_days=#{annualSalaryDays}, max_consecutive_vacation_days=#{maxConsecutiveVacationDays} " +
            "WHERE salary_level_id=#{salaryLevelId}")
    int update(SalaryLevel salaryLevel);

    @Delete("DELETE FROM salary_level WHERE salary_level_id=#{id}")
    int deleteById(Integer id);

    @Select("SELECT * FROM salary_level WHERE salary_level_id=#{id}")
    SalaryLevel selectById(Integer id);

    @Select("SELECT * FROM salary_level")
    List<SalaryLevel> selectAll();

    @Select("SELECT COUNT(*) FROM salary_level WHERE salary_level_name=#{name} AND salary_level_id != #{excludeId}")
    int countByNameExcludeId(@Param("name") String name, @Param("excludeId") Integer excludeId);
}